﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 设计模式.传输对象模式
{
    public class StudentBO
    {
        public List<StudentVO> students;

        public StudentBO()
        {
            students = new List<StudentVO>();
            StudentVO s1 = new StudentVO("Robert", 0);
            StudentVO s2 = new StudentVO("John", 1);

            students.Add(s1);
            students.Add(s2);
        }

        public void DeleteStudent(StudentVO student)
        {
            students.Remove(students.Find(item=>item.RollNo==student.RollNo));
            Console.WriteLine("Student: Roll No " + student.RollNo + ",deleted from database");
        }

        public List<StudentVO> GetAllStudents()
        {
            return students;
        }

        public StudentVO GetStudent(int rollNo)
        {
            return students.Find(item => item.RollNo == rollNo);
        }

        public void UpdateStudent(StudentVO student)
        {
            students.Find(item => item.RollNo == student.RollNo).Name = student.Name;
            Console.WriteLine("Student: Roll No " + student.RollNo + ",updated in the database");
        }
    }
}
